package elven.test.d.common.print;

import java.util.concurrent.ArrayBlockingQueue;

import elven.d.common.log.LogFactory;

public class DSampleQueue {

	public ArrayBlockingQueue<Callback> arrayAndPut() throws Exception{
		ArrayBlockingQueue<Callback> callbackQueue = new ArrayBlockingQueue<Callback>(100);
		Callback callback = null; 
		for(int i = 0; i < 100; i++){
			callback = new Callback() {
				private String type;
				public String put(int i) {
					type = "Current："+i;
					return type;
				}
				public String out() {
					return type;
				}
			};
			callback.put(i);
			callbackQueue.put(callback);
		}
		return callbackQueue;
	}
	
	public static void main(String[] args) {
		try {
			DSampleQueue queue = new DSampleQueue();
			ArrayBlockingQueue<Callback> callbacks = queue.arrayAndPut();
			LogFactory.d().info("Size:"+callbacks.size());
			LogFactory.d().info("Pop："+callbacks.poll().out(),"size："+callbacks.size());
			LogFactory.d().info("Peek："+callbacks.peek().out(),"size："+callbacks.size());
			callbacks.put(new Print(0));
			//callbacks.put(new Print(1));	在put一个就会阻塞掉
			int all = callbacks.size();
			for(int i = 0; i < all; i++){
				LogFactory.d().info(callbacks.take().out());
			}
		} catch (Exception e) {
			LogFactory.d().error(e.getMessage(), e);
		}
	}
	
}